package com.yonyou.pmclouds.plan.entity;

import com.yonyou.pmclouds.basecom.entity.SuperVO;
import com.yonyou.pmclouds.measureindex.entity.MeasureIndexHistoryVO;
import lombok.Getter;
import lombok.Setter;
import org.apache.commons.lang3.ArrayUtils;

import javax.persistence.Id;
import javax.persistence.Table;
import javax.persistence.Transient;
import java.util.Date;

@Getter
@Setter
@Table(name = "pm_plan_prog_his")
public class PlanProgressHistoryVO extends SuperVO {
    @Id
    private String pkProgressHis;
    private String pkPlan;
    private Integer progress;
    private Date startDate;
    private Date endDate;
    private String description;
    private Date creationtime;
    private String creator;
    private String pkPlanwrite;

    private String billType;

    private byte billStatus;

    private int fillCount;

    @Transient
    private MeasureIndexHistoryVO[] measureIndexHistoryVOS;
    @Transient
    private String creatorName;
    @Transient
    private String[] pictures;
    @Transient
    private byte sign;//1 无效 0 有效

    public static PlanProgressHistoryVO convertFromProgress(PlanProgressVO progress) {
        PlanProgressHistoryVO his = new PlanProgressHistoryVO();
        his.pkPlan = progress.getPkPlan();
        his.progress = progress.getProgress();
        his.startDate = progress.getStartDate();
        his.endDate = progress.getEndDate();
        his.creationtime = progress.getModifytime() != null ? progress.getModifytime() : progress.getCreationtime();
        his.creator = progress.getModifier() != null ? progress.getModifier() : progress.getCreator();
        return his;
    }

    public static PlanProgressHistoryVO convertFromProgress(PlanProgressTransVO progress) {
        PlanProgressHistoryVO his = new PlanProgressHistoryVO();
        his.pkPlan = progress.getPkPlan();
        his.progress = progress.getProgress();
        his.startDate = progress.getStartDate();
        his.endDate = progress.getEndDate();
        his.description = progress.getDescription();
        his.pictures = ArrayUtils.clone(progress.getPictures());
        his.creationtime = progress.getModifytime() != null ? progress.getModifytime() : progress.getCreationtime();
        his.creator = progress.getModifier() != null ? progress.getModifier() : progress.getCreator();
        his.pkPlanwrite = progress.getPkPlanwrite();
        return his;
    }
}
